<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/dute_favicon_32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/dute_favicon_16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <link rel="manifest" href="/images/manifest.json">
  <meta name="msapplication-config" content="/images/browserconfig.xml">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="google-site-verification" content="mpI5dkydstZXl6UcDCppqktXK0bbvqdZ6LkZ3KNk4Iw">
  <meta name="baidu-site-verification" content="code-a1LksZX2Ds">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"whitestore.top","root":"/","scheme":"Gemini","version":"7.8.0","exturl":true,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="使用lambada表达式处理">
<meta property="og:type" content="article">
<meta property="og:title" content="【Java】JDK1.8 Lambda 表达式">
<meta property="og:url" content="https://whitestore.top/2020/09/25/note27/index.html">
<meta property="og:site_name" content="爱看书的阿东">
<meta property="og:description" content="使用lambada表达式处理">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20200505103819.png?ynotemdtimestamp=1601045594695">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20200505103923.png?ynotemdtimestamp=1601045594695">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20200505104143.png?ynotemdtimestamp=1601045594695">
<meta property="article:published_time" content="2020-09-25T15:57:19.000Z">
<meta property="article:modified_time" content="2023-07-16T06:28:09.249Z">
<meta property="article:author" content="阿东">
<meta property="article:tag" content="lambada">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20200505103819.png?ynotemdtimestamp=1601045594695">

<link rel="canonical" href="https://whitestore.top/2020/09/25/note27/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>【Java】JDK1.8 Lambda 表达式 | 爱看书的阿东</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="爱看书的阿东" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">爱看书的阿东</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">赐他一块白色石头，石头上写着新名</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://whitestore.top/2020/09/25/note27/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="阿东">
      <meta itemprop="description" content="随遇而安">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="爱看书的阿东">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          【Java】JDK1.8 Lambda 表达式
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-09-25 23:57:19" itemprop="dateCreated datePublished" datetime="2020-09-25T23:57:19+08:00">2020-09-25</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2023-07-16 14:28:09" itemprop="dateModified" datetime="2023-07-16T14:28:09+08:00">2023-07-16</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/09/25/note27/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/09/25/note27/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>9.7k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>9 分钟</span>
            </span>
            <div class="post-description">使用lambada表达式处理</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="【Java】JDK1-8-Lambda-表达式"><a href="#【Java】JDK1-8-Lambda-表达式" class="headerlink" title="【Java】JDK1.8 Lambda 表达式"></a>【Java】JDK1.8 Lambda 表达式</h1><h2 id="简介："><a href="#简介：" class="headerlink" title="简介："></a>简介：</h2><p>现在的工作当中对于jdk1.8的lambada表达式使用越来越频繁，但是对于内部的一些细节却不是特别的清楚</p>
<p>这里借鉴了几篇博客，对比了之后对于博客到推荐进行了排序，同时也整理了这几篇博客提到的个人觉得比较重要到部分进行了验证</p>
<h2 id="第一篇"><a href="#第一篇" class="headerlink" title="第一篇"></a>第一篇</h2><p><strong><span class="exturl" data-url="aHR0cHM6Ly9vYmpjb2RpbmcuY29tLzIwMTkvMDMvMDQvbGFtYmRhLw==" title="https://objcoding.com/2019/03/04/lambda/">https://objcoding.com/2019/03/04/lambda/<i class="fa fa-external-link"></i></span></strong> 一篇博客，介绍的比较到位，虽然文章很长但是通篇看完完全没有想点右上角的冲动</p>
<h2 id="第二篇"><a href="#第二篇" class="headerlink" title="第二篇"></a>第二篇</h2><p><span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uaW0vcG9zdC81YWJjOWNjYzZmYjlhMDI4ZDY2NDNlZWE=" title="https://juejin.im/post/5abc9ccc6fb9a028d6643eea">https://juejin.im/post/5abc9ccc6fb9a028d6643eea<i class="fa fa-external-link"></i></span></p>
<p>关于lambada的十个案例</p>
<h3 id="重点部分："><a href="#重点部分：" class="headerlink" title="重点部分："></a>重点部分：</h3><h4 id="Q：如何在lambda表达式中加入谓词？"><a href="#Q：如何在lambda表达式中加入谓词？" class="headerlink" title="Q：如何在lambda表达式中加入谓词？"></a>Q：如何在lambda表达式中加入谓词？</h4><h3 id="A：解答"><a href="#A：解答" class="headerlink" title="A：解答"></a>A：解答</h3><p>首先代码如下，按照个人理解，其实本质就是把用户的操作“拼接”，包括筛选，合并等操作，依赖<code>java.util.function.Predicate</code>此接口实现</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 甚至可以用and()、or()逻辑函数来合并Predicate，</span><br><span class="line">&#x2F;&#x2F; 例如要找到所有以J开始，长度为四个字母的名字，你可以合并两个Predicate并传入</span><br><span class="line">Predicate&lt;String&gt; startsWithJ &#x3D; (n) -&gt; n.startsWith(&quot;J&quot;);</span><br><span class="line">Predicate&lt;String&gt; fourLetterLong &#x3D; (n) -&gt; n.length() &#x3D;&#x3D; 4;</span><br><span class="line">names.stream()</span><br><span class="line">    .filter(startsWithJ.and(fourLetterLong))</span><br><span class="line">    .forEach((n) -&gt; System.out.print(&quot;nName, which starts with &#39;J&#39; and four letter long is : &quot; + n));</span><br></pre></td></tr></table></figure>

<h2 id="第三篇"><a href="#第三篇" class="headerlink" title="第三篇"></a>第三篇</h2><p><span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL2EvMTE5MDAwMDAwOTE4NjUwOQ==" title="https://segmentfault.com/a/1190000009186509">https://segmentfault.com/a/1190000009186509<i class="fa fa-external-link"></i></span></p>
<p>关于lambada的一个详解</p>
<blockquote>
<p>版权声明：本文由<em>吴仙杰</em>创作整理，转载请注明出处：<span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL2EvMTE5MDAwMDAwOTE4NjUwOQ==" title="https://segmentfault.com/a/1190000009186509">https://segmentfault.com/a/1190000009186509<i class="fa fa-external-link"></i></span></p>
</blockquote>
<h2 id="第四篇"><a href="#第四篇" class="headerlink" title="第四篇"></a>第四篇</h2><p><span class="exturl" data-url="aHR0cHM6Ly93d3cub3JhY2xlLmNvbS93ZWJmb2xkZXIvdGVjaG5ldHdvcmsvdHV0b3JpYWxzL29iZS9qYXZhL0xhbWJkYS1RdWlja1N0YXJ0L2luZGV4Lmh0bWw=" title="https://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html">https://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html<i class="fa fa-external-link"></i></span></p>
<p>Oracale官方案例</p>
<p><span class="exturl" data-url="aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3JlbmZ1ZmVpL2FydGljbGUvZGV0YWlscy8yNDYwMDUwNw==" title="https://blog.csdn.net/renfufei/article/details/24600507">https://blog.csdn.net/renfufei/article/details/24600507<i class="fa fa-external-link"></i></span></p>
<p>比较久远到一个文章，更多是批判的角度看待lambada</p>
<a id="more"></a>

<h2 id="概览"><a href="#概览" class="headerlink" title="概览"></a>概览</h2><ol>
<li>介绍了stream 的基本概念<ol>
<li>简写的依据 - 函数接口 和类型推断机制</li>
</ol>
</li>
<li>函数式编程和匿名内部类的区别<ol>
<li>使用上区别</li>
<li>JVM上的本质区别</li>
</ol>
</li>
<li>JDK8 对于容器到扩展方法，其中部分是为了配合函数式编程而出现的<ol>
<li>Collections</li>
<li>Map</li>
</ol>
</li>
<li>Stream API 介绍stream 的常用方法以及基本特性<ol>
<li><code>sort()</code></li>
<li></li>
</ol>
</li>
<li>stream内部实现的简单了解<ol>
<li>用户的操作如何记录？</li>
<li>操作如何叠加？</li>
<li>叠加之后的操作如何执行？</li>
<li>执行后的结果（如果有）在哪里？</li>
</ol>
</li>
</ol>
<h2 id="重点部分"><a href="#重点部分" class="headerlink" title="重点部分"></a>重点部分</h2><h3 id="Q：匿名内部类和lambada表达式的关键区别"><a href="#Q：匿名内部类和lambada表达式的关键区别" class="headerlink" title="Q：匿名内部类和lambada表达式的关键区别"></a>Q：匿名内部类和lambada表达式的关键区别</h3><h3 id="A-回答"><a href="#A-回答" class="headerlink" title="A 回答"></a>A 回答</h3><h4 id="this的指向对象"><a href="#this的指向对象" class="headerlink" title="this的指向对象"></a><strong>this</strong>的指向对象</h4><ul>
<li>匿名内部类：<code>this</code> 指向的是匿名内部类的所属对象</li>
<li>lambada：<code>this</code> 指向当前运行的类，也就是当前运行的对象</li>
</ul>
<h4 id="jvm层面"><a href="#jvm层面" class="headerlink" title="jvm层面"></a>jvm层面</h4><ul>
<li>匿名内部类：会生成一个 <code>$1</code>到匿名内部类的对象，使用<code>new</code>指令生成对象并且执行</li>
<li>lambada：会生成一个私有方法，使用<code>invokedynamic</code>指令调用</li>
</ul>
<p>匿名内部类的编译过程</p>
<p>为了更好到理解，自己做了一个实验</p>
<ol>
<li>创建一个基本的匿名内部类到方法</li>
</ol>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20200505103819.png?ynotemdtimestamp=1601045594695" alt="img"></p>
<p>代码如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;**</span><br><span class="line">     * 匿名内部类和lambada的区别</span><br><span class="line">     *&#x2F;</span><br><span class="line">    @Test</span><br><span class="line">    public void test1() throws InterruptedException &#123;</span><br><span class="line">        new Thread(new Runnable() &#123;</span><br><span class="line">            public void run() &#123;</span><br><span class="line">                String name &#x3D; Thread.currentThread().getName();</span><br><span class="line">                System.err.println(name + &quot; is run as a thread &quot;);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;).start();</span><br><span class="line">        Thread.sleep(2000);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<ol>
<li>查看classes ，可以看到编译后的class 文件如下，看到明显多出来一个<code>LambadaTest1$1.class</code> 这事啥东西？</li>
</ol>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20200505103923.png?ynotemdtimestamp=1601045594695" alt="img"></p>
<ol>
<li>打开<code>cmd</code>使用<code>cd</code>命令移动到改目录下面</li>
</ol>
<blockquote>
<p>小技巧1：</p>
<p>编译后到classes 如果想要直接查看class 文件的反编译到内容，可以直接把class 文件拖拽到 idea 里面进行打开，就可以看到class 到反编译内容<del>~</del></p>
</blockquote>
<ol>
<li>反编译的内容如下，可以看到匿名内部类的编译后的内容经过解释之后，<strong>实际上是创建了一个匿名内部类的对象</strong></li>
</ol>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20200505104143.png?ynotemdtimestamp=1601045594695" alt="img"></p>
<ol>
<li>在第一步的基础上，我们除了打印线程的名称，还可以打印<code>this</code> 看一下匿名内部类的this 是啥东西，我打印之后得到到匿名内部类的 this 如下: <code>com.jdk.lambada.LambadaTest1$1@2fd014c6</code></li>
</ol>
<blockquote>
<p>小技巧2：</p>
<p>如何使用javap 查看java的汇编指令呢？</p>
<p>以上面到案例为例：</p>
<ol>
<li>打开<code>cmd</code>，进入对应的class目录，我们可以执行<code>javap &lt;options&gt; &lt;classes&gt;</code>的格式进行翻译操作</li>
<li>执行<code>javap -c -l -p xxx</code>，得到结果:</li>
</ol>
<p>选项的含义？</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">-help  --help  -?        输出此用法消息</span><br><span class="line">-version                 版本信息，其实是当前javap所在jdk的版本信息，不是class在哪个jdk下生成的。</span><br><span class="line">-v  -verbose             输出附加信息（包括行号、本地变量表，反汇编等详细信息）</span><br><span class="line">-l                         输出行号和本地变量表</span><br><span class="line">-public                    仅显示公共类和成员</span><br><span class="line">-protected               显示受保护的&#x2F;公共类和成员</span><br><span class="line">-package                 显示程序包&#x2F;受保护的&#x2F;公共类 和成员 (默认)</span><br><span class="line">-p  -private             显示所有类和成员</span><br><span class="line">-c                       对代码进行反汇编</span><br><span class="line">-s                       输出内部类型签名</span><br><span class="line">-sysinfo                 显示正在处理的类的系统信息 (路径, 大小, 日期, MD5 散列)</span><br><span class="line">-constants               显示静态最终常量</span><br><span class="line">-classpath &lt;path&gt;        指定查找用户类文件的位置</span><br><span class="line">-bootclasspath &lt;path&gt;    覆盖引导类文件的位置</span><br></pre></td></tr></table></figure>
</blockquote>
<ol>
<li>为了更进一步了解底层的jvm指令执行，使用<code>javap -c -l -p xxx</code>反编译结果如下</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">Compiled from &quot;LambadaTest1.java&quot;</span><br><span class="line">public class com.jdk.lambada.LambadaTest1 &#123;</span><br><span class="line">  public com.jdk.lambada.LambadaTest1();</span><br><span class="line">    Code:</span><br><span class="line">       0: aload_0</span><br><span class="line">       1: invokespecial #1                  &#x2F;&#x2F; Method java&#x2F;lang&#x2F;Object.&quot;&lt;init&gt;&quot;:()V</span><br><span class="line">       4: return</span><br><span class="line">    LineNumberTable:</span><br><span class="line">      line 11: 0</span><br><span class="line">    LocalVariableTable:</span><br><span class="line">      Start  Length  Slot  Name   Signature</span><br><span class="line">          0       5     0  this   Lcom&#x2F;jdk&#x2F;lambada&#x2F;LambadaTest1;</span><br><span class="line"></span><br><span class="line">  public void test1() throws java.lang.InterruptedException;</span><br><span class="line">    Code:</span><br><span class="line">       0: new           #2                  &#x2F;&#x2F; class java&#x2F;lang&#x2F;Thread</span><br><span class="line">       3: dup</span><br><span class="line">       4: new           #3                  &#x2F;&#x2F; class com&#x2F;jdk&#x2F;lambada&#x2F;LambadaTest1$1</span><br><span class="line">       7: dup</span><br><span class="line">       8: aload_0</span><br><span class="line">       9: invokespecial #4                  &#x2F;&#x2F; Method com&#x2F;jdk&#x2F;lambada&#x2F;LambadaTest1$1.&quot;&lt;init&gt;&quot;:(Lcom&#x2F;jdk&#x2F;lambada&#x2F;LambadaTest1;)V</span><br><span class="line">      12: invokespecial #5                  &#x2F;&#x2F; Method java&#x2F;lang&#x2F;Thread.&quot;&lt;init&gt;&quot;:(Ljava&#x2F;lang&#x2F;Runnable;)V</span><br><span class="line">      15: invokevirtual #6                  &#x2F;&#x2F; Method java&#x2F;lang&#x2F;Thread.start:()V</span><br><span class="line">      18: ldc2_w        #7                  &#x2F;&#x2F; long 2000l</span><br><span class="line">      21: invokestatic  #9                  &#x2F;&#x2F; Method java&#x2F;lang&#x2F;Thread.sleep:(J)V</span><br><span class="line">      24: return</span><br><span class="line">    LineNumberTable:</span><br><span class="line">      line 19: 0</span><br><span class="line">      line 24: 15</span><br><span class="line">      line 25: 18</span><br><span class="line">      line 27: 24</span><br><span class="line">    LocalVariableTable:</span><br><span class="line">      Start  Length  Slot  Name   Signature</span><br><span class="line">          0      25     0  this   Lcom&#x2F;jdk&#x2F;lambada&#x2F;LambadaTest1;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>可以发现，匿名内部类使用了 <code>new</code>到指令来实现匿名对象的生成，调用<code>invokespecial</code>执行内部的<code>run</code>方法</p>
<p>接下来我们看下Lambada简写上面的匿名内部类代码</p>
<p>lambada表达式编译过程</p>
<ol>
<li>和上面的流程类似，这里直接略过一些不必要的点，代码如下</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">import java.util.concurrent.TimeUnit;</span><br><span class="line"></span><br><span class="line">&#x2F;**</span><br><span class="line"> * @program: lambada</span><br><span class="line"> * @description: 测试jdk1.8</span><br><span class="line"> * @author: zhaoxudong</span><br><span class="line"> * @create: 2020-05-05 11:42</span><br><span class="line"> **&#x2F;</span><br><span class="line">public class Test &#123;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">        new Thread(()-&gt;&#123;</span><br><span class="line">            System.err.println(&quot; test&quot; + Thread.currentThread().getName() + &quot; is run as a thread &quot; );</span><br><span class="line">        &#125;).start();</span><br><span class="line">        TimeUnit.SECONDS.sleep(5L);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol>
<li>同样的，我们先把class文件放到<code>idea</code>下面查看反编译之后到代码</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;</span><br><span class="line">&#x2F;&#x2F; Source code recreated from a .class file by IntelliJ IDEA</span><br><span class="line">&#x2F;&#x2F; (powered by Fernflower decompiler)</span><br><span class="line">&#x2F;&#x2F;</span><br><span class="line"></span><br><span class="line">import java.util.concurrent.TimeUnit;</span><br><span class="line"></span><br><span class="line">public class Test &#123;</span><br><span class="line">    public Test() &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">        (new Thread(() -&gt; &#123;</span><br><span class="line">            System.err.println(&quot; test&quot; + Thread.currentThread().getName() + &quot; is run as a thread &quot;);</span><br><span class="line">        &#125;)).start();</span><br><span class="line">        TimeUnit.SECONDS.sleep(5L);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol>
<li>打开class所在目录，我们会发现lambada并没有像匿名内部类一样创建了一个$1 的对象，那么他是如何实现的？</li>
<li>我们使用<code>javap -c -l -p xxx</code> 翻译class 得到到结果如下</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">public class Test &#123;</span><br><span class="line">  public Test();</span><br><span class="line">    Code:</span><br><span class="line">       0: aload_0</span><br><span class="line">       1: invokespecial #1                  &#x2F;&#x2F; Method java&#x2F;lang&#x2F;Object.&quot;&lt;init&gt;&quot;:()V</span><br><span class="line">       4: return</span><br><span class="line">    LineNumberTable:</span><br><span class="line">      line 9: 0</span><br><span class="line">    LocalVariableTable:</span><br><span class="line">      Start  Length  Slot  Name   Signature</span><br><span class="line">          0       5     0  this   LTest;</span><br><span class="line"></span><br><span class="line">  public static void main(java.lang.String[]) throws java.lang.InterruptedException;</span><br><span class="line">    Code:</span><br><span class="line">       0: new           #2                  &#x2F;&#x2F; class java&#x2F;lang&#x2F;Thread</span><br><span class="line">       3: dup</span><br><span class="line">       4: invokedynamic #3,  0              &#x2F;&#x2F; InvokeDynamic #0:run: ()Ljava&#x2F;lang&#x2F;Runnable;</span><br><span class="line">       9: invokespecial #4                  &#x2F;&#x2F; Method java&#x2F;lang&#x2F;Thread.&quot;&lt;init&gt;&quot;:(Ljava&#x2F;lang&#x2F;Runnable;)V</span><br><span class="line">      12: invokevirtual #5                  &#x2F;&#x2F; Method java&#x2F;lang&#x2F;Thread.start:()V</span><br><span class="line">      15: getstatic     #6                  &#x2F;&#x2F; Field java&#x2F;util&#x2F;concurrent&#x2F;TimeUnit.SECONDS:Ljava&#x2F;util&#x2F;concurrent&#x2F;TimeUnit;</span><br><span class="line">      18: ldc2_w        #7                  &#x2F;&#x2F; long 5l</span><br><span class="line">      21: invokevirtual #9                  &#x2F;&#x2F; Method java&#x2F;util&#x2F;concurrent&#x2F;TimeUnit.sleep:(J)V</span><br><span class="line">      24: return</span><br><span class="line">    LineNumberTable:</span><br><span class="line">      line 12: 0</span><br><span class="line">      line 14: 12</span><br><span class="line">      line 15: 15</span><br><span class="line">      line 16: 24</span><br><span class="line">    LocalVariableTable:</span><br><span class="line">      Start  Length  Slot  Name   Signature</span><br><span class="line">          0      25     0  args   [Ljava&#x2F;lang&#x2F;String;</span><br><span class="line"></span><br><span class="line">  private static void lambda$main$0();</span><br><span class="line">    Code:</span><br><span class="line">       0: getstatic     #10                 &#x2F;&#x2F; Field java&#x2F;lang&#x2F;System.err:Ljava&#x2F;io&#x2F;PrintStream;</span><br><span class="line">       3: new           #11                 &#x2F;&#x2F; class java&#x2F;lang&#x2F;StringBuilder</span><br><span class="line">       6: dup</span><br><span class="line">       7: invokespecial #12                 &#x2F;&#x2F; Method java&#x2F;lang&#x2F;StringBuilder.&quot;&lt;init&gt;&quot;:()V</span><br><span class="line">      10: ldc           #13                 &#x2F;&#x2F; String  test</span><br><span class="line">      12: invokevirtual #14                 &#x2F;&#x2F; Method java&#x2F;lang&#x2F;StringBuilder.append:(Ljava&#x2F;lang&#x2F;String;)Ljava&#x2F;lang&#x2F;StringBuilder;</span><br><span class="line">      15: invokestatic  #15                 &#x2F;&#x2F; Method java&#x2F;lang&#x2F;Thread.currentThread:()Ljava&#x2F;lang&#x2F;Thread;</span><br><span class="line">      18: invokevirtual #16                 &#x2F;&#x2F; Method java&#x2F;lang&#x2F;Thread.getName:()Ljava&#x2F;lang&#x2F;String;</span><br><span class="line">      21: invokevirtual #14                 &#x2F;&#x2F; Method java&#x2F;lang&#x2F;StringBuilder.append:(Ljava&#x2F;lang&#x2F;String;)Ljava&#x2F;lang&#x2F;StringBuilder;</span><br><span class="line">      24: ldc           #17                 &#x2F;&#x2F; String  is run as a thread</span><br><span class="line">      26: invokevirtual #14                 &#x2F;&#x2F; Method java&#x2F;lang&#x2F;StringBuilder.append:(Ljava&#x2F;lang&#x2F;String;)Ljava&#x2F;lang&#x2F;StringBuilder;</span><br><span class="line">      29: invokevirtual #18                 &#x2F;&#x2F; Method java&#x2F;lang&#x2F;StringBuilder.toString:()Ljava&#x2F;lang&#x2F;String;</span><br><span class="line">      32: invokevirtual #19                 &#x2F;&#x2F; Method java&#x2F;io&#x2F;PrintStream.println:(Ljava&#x2F;lang&#x2F;String;)V</span><br><span class="line">      35: return</span><br><span class="line">    LineNumberTable:</span><br><span class="line">      line 13: 0</span><br><span class="line">      line 14: 35</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>对比匿名内部类和lambada表达式可以明显发现，Lambada的不同在于使用了<code>私有方法</code> 加上 <code>invokedynamic</code>指令进行编译，而不会产生一个匿名内部类的对象class文件。</p>
<ol>
<li>我们可以看下Lambada的 <code>this</code>打印的是什么东西</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">        new Thread(()-&gt;&#123;</span><br><span class="line">            System.err.println(&quot; test&quot; + Thread.currentThread().getName() + &quot; is run as a thread &quot; );</span><br><span class="line">            System.err.println(&quot;lambada this is &#x3D; &quot; + this);</span><br><span class="line">        &#125;).start();</span><br><span class="line">        TimeUnit.SECONDS.sleep(5L);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p><strong>这里惊讶的发现,编译居然无法通过！！！！</strong></p>
<p>我们再对比使用匿名内部类的方式：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">    new Thread(new Runnable() &#123;</span><br><span class="line">        public void run() &#123;</span><br><span class="line">            String name &#x3D; Thread.currentThread().getName();</span><br><span class="line">            System.err.println(name + &quot; is run as a thread &quot; + this);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;).start();</span><br><span class="line">    Thread.sleep(2000);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>此方式可以正常编译通过并且运行，由此我们可以发现lambada的<code>this</code> 和匿名内部类的 <code>this</code>有着本质的区别</p>
<ol>
<li>我们无法使用正常到方式打印this, 我们换一种方式，这里稍微调整代码，最后的代码如下:</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;**</span><br><span class="line"> * @program: lambada</span><br><span class="line"> * @description: 测试jdk1.8</span><br><span class="line"> * @author: zhaoxudong</span><br><span class="line"> * @create: 2020-05-05 11:42</span><br><span class="line"> **&#x2F;</span><br><span class="line">public class Test &#123;</span><br><span class="line"></span><br><span class="line">    Runnable run &#x3D; () -&gt;&#123;</span><br><span class="line">        System.err.println(this);</span><br><span class="line">    &#125;;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">        new Thread(new Test().run).start();</span><br><span class="line">        TimeUnit.SECONDS.sleep(5L);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public String toString() &#123;</span><br><span class="line">        return &quot;test&quot;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>执行上面的代码，可以得到结果<code>test</code></p>
<blockquote>
<p>在匿名内部类如何得到结果呢？</p>
<p>可以看下面的代码，结果依然是打印 <code>test</code></p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;**</span><br><span class="line"> * @program: smartframwork</span><br><span class="line"> * @description: lambada表达式学习1</span><br><span class="line"> * @author: zhaoxudong</span><br><span class="line"> * @create: 2020-05-05 10:29</span><br><span class="line"> **&#x2F;</span><br><span class="line">public class LambadaTest1 &#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">        new Thread(new Runnable() &#123;</span><br><span class="line">            public void run() &#123;</span><br><span class="line">                String name &#x3D; Thread.currentThread().getName();</span><br><span class="line">                System.err.println(name + &quot; is run as a thread &quot; + this);</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            @Override</span><br><span class="line">            public String toString() &#123;</span><br><span class="line">                return &quot;test&quot;;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;).start();</span><br><span class="line">        Thread.sleep(2000);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public String toString() &#123;</span><br><span class="line">        return &quot;LambadaTest1&#123;&#125;&quot;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>结论：</p>
<p>匿名内部类：<code>this</code> 指向的是匿名内部类的所属对象（<strong>也就是Runnable</strong>）</p>
<p>lambada：<code>this</code> 指向当前运行的类（<strong>也就是Test</strong>），也就是当前运行的对象</p>
<h3 id="Q：Java8里面的java-util-Spliterator接口有什么用？"><a href="#Q：Java8里面的java-util-Spliterator接口有什么用？" class="headerlink" title="Q：Java8里面的java.util.Spliterator接口有什么用？"></a>Q：Java8里面的java.util.Spliterator接口有什么用？</h3><h3 id="A：参考博客"><a href="#A：参考博客" class="headerlink" title="A：参考博客"></a>A：参考博客</h3><p><span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL3EvMTAxMDAwMDAwNzA4NzQzOA==" title="https://segmentfault.com/q/1010000007087438">思否<i class="fa fa-external-link"></i></span></p>
<p>一句话概括：为了多线程并行遍历元素而设计到迭代器</p>
<p>版本：JDK1.8</p>
<p>目的：简化复杂到并行迭代程序编写</p>
<p>参考：Java7的Fork/Join(分支/合并)框架</p>
<p><span class="exturl" data-url="aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbHZlcjk4ODYvYXJ0aWNsZS9kZXRhaWxzLzg3OTE3ODIz" title="https://blog.csdn.net/silver9886/article/details/87917823">CSDN上面到解答<i class="fa fa-external-link"></i></span></p>
<p><span class="exturl" data-url="aHR0cHM6Ly9pZmV2ZS5jb20vamF2YTgtc3RyZWFtLeS4rXNwbGl0ZXJhdG9y55qE5L2/55So5LiALw==" title="https://ifeve.com/java8-stream-中spliterator的使用一/">JAVA8 stream 中Spliterator的使用(一)<i class="fa fa-external-link"></i></span></p>
<p><span class="exturl" data-url="aHR0cHM6Ly9pZmV2ZS5jb20vamF2YTgtc3RyZWFtLeS4rXNwbGl0ZXJhdG9y55qE5L2/55So5LqMLw==" title="https://ifeve.com/java8-stream-中spliterator的使用二/">JAVA8 stream 中Spliterator的使用(二)<i class="fa fa-external-link"></i></span></p>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css">
    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>lazytime
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://whitestore.top/2020/09/25/note27/" title="【Java】JDK1.8 Lambda 表达式">https://whitestore.top/2020/09/25/note27/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLzQuMC96aC1DTg=="><i class="fa fa-fw fa-creative-commons"></i>BY-NC</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Java/" rel="tag"># Java</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/09/25/note26/" rel="prev" title="Mindoc 安装与部署">
      <i class="fa fa-chevron-left"></i> Mindoc 安装与部署
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/10/07/note28/" rel="next" title="模仿游戏-观后感">
      模仿游戏-观后感 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#【Java】JDK1-8-Lambda-表达式"><span class="nav-number">1.</span> <span class="nav-text">【Java】JDK1.8 Lambda 表达式</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#简介："><span class="nav-number">1.1.</span> <span class="nav-text">简介：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#第一篇"><span class="nav-number">1.2.</span> <span class="nav-text">第一篇</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#第二篇"><span class="nav-number">1.3.</span> <span class="nav-text">第二篇</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#重点部分："><span class="nav-number">1.3.1.</span> <span class="nav-text">重点部分：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Q：如何在lambda表达式中加入谓词？"><span class="nav-number">1.3.1.1.</span> <span class="nav-text">Q：如何在lambda表达式中加入谓词？</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#A：解答"><span class="nav-number">1.3.2.</span> <span class="nav-text">A：解答</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#第三篇"><span class="nav-number">1.4.</span> <span class="nav-text">第三篇</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#第四篇"><span class="nav-number">1.5.</span> <span class="nav-text">第四篇</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#概览"><span class="nav-number">1.6.</span> <span class="nav-text">概览</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#重点部分"><span class="nav-number">1.7.</span> <span class="nav-text">重点部分</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Q：匿名内部类和lambada表达式的关键区别"><span class="nav-number">1.7.1.</span> <span class="nav-text">Q：匿名内部类和lambada表达式的关键区别</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#A-回答"><span class="nav-number">1.7.2.</span> <span class="nav-text">A 回答</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#this的指向对象"><span class="nav-number">1.7.2.1.</span> <span class="nav-text">this的指向对象</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#jvm层面"><span class="nav-number">1.7.2.2.</span> <span class="nav-text">jvm层面</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Q：Java8里面的java-util-Spliterator接口有什么用？"><span class="nav-number">1.7.3.</span> <span class="nav-text">Q：Java8里面的java.util.Spliterator接口有什么用？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#A：参考博客"><span class="nav-number">1.7.4.</span> <span class="nav-text">A：参考博客</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">阿东</p>
  <div class="site-description" itemprop="description">随遇而安</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">239</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">36</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">37</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;lazyTimes"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOjEwOTc0ODM1MDhAcXEuY29t" title="E-Mail → mailto:1097483508@qq.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly93d3cuNTJwb2ppZS5jbi9ob21lLnBocD9tb2Q9c3BhY2UmdWlkPTE0OTc3MTgmZG89dGhyZWFkJnZpZXc9bWUmZnJvbT1zcGFjZQ==" title="https:&#x2F;&#x2F;www.52pojie.cn&#x2F;home.php?mod&#x3D;space&amp;uid&#x3D;1497718&amp;do&#x3D;thread&amp;view&#x3D;me&amp;from&#x3D;space">吾爱破解</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uaW0vdXNlci8yOTk5MTIzNDUyNjI2MzY2" title="https:&#x2F;&#x2F;juejin.im&#x2F;user&#x2F;2999123452626366">掘金</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL3UvbGF6eXRpbWVz" title="https:&#x2F;&#x2F;segmentfault.com&#x2F;u&#x2F;lazytimes">思否</span>
        </li>
    </ul>
  </div>

      </div>

      <div class="wechat_OA">
        <span>欢迎关注我的公众号</span>
        <br>
          <!-- 这里添加你的二维码图片 -->
        <img src ="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/wechat_channel.jpg">
      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">阿东</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">2m</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">29:50</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'qMUpEEvBgXaMDD1b0ftgi9xr-gzGzoHsz',
      appKey     : 'UCdfT4Rfih6MO6y8DI4fstf6',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
